# step 1: 安装必要的一些系统工具
yum remove docker docker-common docker-selinux docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
RELEASE=$(rpm -q centos-release | cut -d '-' -f 3)
if [ "$RELEASE" = "6" ];
then
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum clean all
yum makecache
elif [ "$RELEASE" = "7" ];
then
curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo
cp -a /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
sed -i "s/#baseurl/baseurl/g" /etc/yum.repos.d/epel.repo
sed -i "s/metalink/#metalink/g" /etc/yum.repos.d/epel.repo
sed -i "s@https\?://download.fedoraproject.org/pub@https://repo.huaweicloud.com@g" /etc/yum.repos.d/epel.repo
yum clean all
yum makecache
elif [ "$RELEASE" = "8" ];
then
curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-8-reg.repo
curl -o /etc/yum.repos.d/docker-ce.repo https://repo.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+repo.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
#rpm -ivh https://mirrors.aliyun.com/epel/epel-release-latest-8.noarch.rpm
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub|baseurl=https://mirrors.aliyun.com|' /etc/yum.repos.d/epel*
sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel*
yum makecache fast
fi

sudo yum install -y  yum-utils device-mapper-persistent-data lvm2 vim wget python3 vim wget lsof git 
 
# Step 2: 更新并安装Docker-CE
if [ "$RELEASE" = "8" ];
then
dnf install -y python3-devel  && ln -s /usr/bin/pip3 /usr/bin/pip
yum install install docker-ce
else
wget -O /etc/yum.repos.d/docker-ce.repo https://repo.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
sudo sed -i 's+download.docker.com+repo.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
sudo yum makecache fast
yum -y install docker-ce python-pip
fi

# Step 3: 添加DOCKER加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{ "registry-mirrors": ["https://r2xanz27.mirror.aliyuncs.com"] }
EOF
# Step 4: 开启Docker服务
sudo systemctl daemon-reload
sudo systemctl restart docker
sudo systemctl enable docker
mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
index-url = https://repo.huaweicloud.com/repository/pypi/simple
trusted-host = repo.huaweicloud.com
timeout = 120
EOF
pip3 --version
pip3 install --upgrade pip
pip3 install docker-compose==1.29.2
docker-compose version
